<template>
  <el-drawer
    title="教师空闲时间"
    :visible.sync="dialogFormVisible"
    size="80%"
    @close="close"
  >
    <el-form ref="form" :model="formData" label-width="100px">
      <el-form-item label="选择教师">
        <el-select v-model="formData.teacherId" placeholder="请选择教师">
          <el-option
            v-for="item in teacherList"
            :key="item.id"
            :label="item.username"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <FullCalendar :options="calendarOptions" />
  </el-drawer>
</template>

<script>
  import FullCalendar from '@fullcalendar/vue'
  import timeGridPlugin from '@fullcalendar/timegrid'
  import zhLocale from '@fullcalendar/core/locales/zh-cn'
  import { format } from 'date-fns'
  import { getTeacherByPage } from '@/apis/teacher'

  export default {
    name: 'CourseCalendar',
    components: {
      FullCalendar,
    },
    data() {
      const now = format(Date.now(), 'yyyy-MM-dd')

      return {
        calendarOptions: {
          plugins: [timeGridPlugin],
          initialView: 'timeGridWeek',
          nowIndicator: true,
          dayHeaders: false,
          slotDuration: '00:30',
          slotMinTime: '08:00:00',
          slotMaxTime: '23:00:00',
          events: [
            {
              start: `${now}T10:00:00`,
              end: `${now}T11:00:00`,
            },
          ],
          locale: zhLocale,
        },
        teacherList: [],
        formData: {
          teacherId: null,
        },
        dialogFormVisible: false,
      }
    },
    created() {
      getTeacherByPage().then(({ data }) => {
        this.teacherList = data
      })
    },
    methods: {
      open() {
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.dialogFormVisible = false
      },
    },
  }
</script>

<style lang="scss" scoped>
  .fc-media-screen {
    padding: 20px;
  }
</style>
